package it.sandler.android.database;

/**
 * You can do what ever you want to do with SandlerDB.<br>
 * There are no restrictions. You can use SandlerDB for commercial use.<br>
 * <br>
 * Circle me on Google+: http://gplus.to/roberthahn<br>
 * SandlerDB on Google Code: http://code.google.com/p/sandler-db-for-android/<br>
 * <br>
 * Date: 04/17/2012
 * 
 * @author Robert Hahn
 * 
 */
public class SandlerRelation<T extends SandlerEntity, E extends SandlerEntity> {

	private final T item;
	private final E item1;

	protected SandlerRelation(T item, E item1) {
		this.item = item;
		this.item1 = item1;
	}

	@SuppressWarnings("unchecked")
	public <B extends SandlerEntity> B get(Class<B> entityClass) {
		if (getFirstItem() != null
				&& getFirstItem().getClass().getSimpleName()
						.equals(entityClass.getSimpleName()))
			return (B) getFirstItem();
		return (B) getSecondItem();
	}

	public T getFirstItem() {
		return item;
	}

	public E getSecondItem() {
		return item1;
	}

}
